<%@page import="java.util.Calendar"%>
<%@page import="com.qijia.travel.helper.DateHelper"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.vo.*"  %>
<%@ page import="java.math.*"  %>
<%@page import="com.qijia.travel.helper.ObjectHelper"%>
<%@ page import="com.qijia.travel.common.*"  %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Guide guide = (Guide)session.getAttribute(Constants.USER_KEY);
if(guide.getGuideType()==null||guide.getGuideType()!=1){
out.println("<script>alert('你没有此权限，请联系管理员开通此权限!');window.close();</script>");
response.sendRedirect(basePath+"baseInfo/home.jsp");
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title>后台管理平台--旅游网</title>
<link rel="stylesheet" type="text/css" href="../css/layout.css" />
<script language="javascript" type="text/javascript" src="<%=basePath%>js/selectall.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/trchgcolor.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/DownPullMenu.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/listOrder.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/displayLayer.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/calendar.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/popupdiv_shim.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/ajaxPopup.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/ymPrompt/skin/qq/ymPrompt.css" />
<script type="text/javascript" src="<%=basePath%>js/ymPrompt/ymPrompt.js"></script>
</head>
<%
request.setCharacterEncoding("UTF-8");
TouristManager manager = new TouristManager();
StatisticsVo vo = (StatisticsVo)ObjectHelper.ConvertURLRequsetMapToObj(request.getParameterMap(),StatisticsVo.class);

if(null==vo.getStDate() || null==vo.getEdDate()){
  Calendar today = Calendar.getInstance(); 
  today.add(Calendar.MONTH,-2);
  vo.setStDate(DateHelper.getThisMonthFirstDay(today));
  vo.setEdDate(DateHelper.getMonthEndDay());
}

if(null==vo.getDateCode()){
 vo.setDateCode(Constants.DATETYPE_GROUP_START_DATE_CODE);
}
PageResult pageObj = manager.selectStatisticsForPage(vo);
RewardProfit rewardProfit = manager.getRewardProfitByStatistics(vo);
BigDecimal personGetTotal = new BigDecimal(0);
BigDecimal groupJun = new BigDecimal(0);
boolean showAll=true;
if(vo.getSearchCode()!=null && Constants.SEARCH_GUIDE_TYPE_CODE == vo.getSearchCode()&&"2".equals(vo.getSearchKeyword())){
showAll=false;
}
try{ 
 groupJun=rewardProfit.getProfitTotal().multiply(rewardProfit.getProfitTotalPercent()).divide(new BigDecimal(rewardProfit.getTotalGroupNum()),BigDecimal.ROUND_HALF_EVEN).setScale(2, BigDecimal.ROUND_HALF_UP);
  }catch(Exception e){
  e.printStackTrace();
 }
if(rewardProfit==null)out.println("<script>alert('获取统计数据出错');window.close();window.parent.location.reload();</script>");




 %>
 <c:set var="vo" value="<%=vo%>" />
<body>
<div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="../common/TopMenu.jsp" flush="true"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：财务统计信息管理 &gt; 组员效益信息</div>
	<div id="REC_content">
	    <fieldset id="TalentLib" class="mainField">
		    <legend><span class="title">组员效益信息</span></legend>
			<div class="innerCon">
			    <form name="TalentLibForm" action="" method="post">
				<!--表头搜索条开始-->
				<div class="mainSearchBox">
				<table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
					<tr height="35">
						<td width="80" class="title">关键字</td>
						<td  colspan="3" align="left">
						<select name="searchCode">
							<option value="1" <%if(null!=vo.getSearchCode()&&vo.getSearchCode()==1)out.print("selected");%>>导游姓名</option>
							<option value="3" <%if(null!=vo.getSearchCode()&&vo.getSearchCode()==3)out.print("selected");%>>导游编号</option>
							<option value="8" <%if(null!=vo.getSearchCode()&&vo.getSearchCode()==8)out.print("selected");%>>导游类型</option>
						</select> 
						<input type="text" name="searchKeyword" value="<%=vo.getSearchKeyword()==null?"":vo.getSearchKeyword()%>" size="70" /></td>
						<td width="160">
						  <input type="submit" name="searchButton" class="newSearchButton" value="查询" onclick="document.TalentLibForm.action='<%=basePath%>work/statistics.jsp';"/> 
						</td>
					</tr>
					<tr id="moresearchCon">
						<td class="title" height="30">日期</td>
						<td colspan="4">
						<select name="dateCode">
							<option value="3" <%if(null!=vo.getDateCode()&&vo.getDateCode()==3)out.print("selected");%>>起始日期</option>
							<option value="4" <%if(null!=vo.getDateCode()&&vo.getDateCode()==4)out.print("selected");%>>截止日期</option>
						</select>
						<input type="text" id="startImg" name="stDate" size="10" readonly="readonly" value="<%=vo.getStDate()==null?"":vo.getStDate()%>" onclick="fPopCalendar(document.getElementById('startImg'),document.getElementById('startImg'));return false;" onkeydown="iniTxt_OnKeydown(event,this);" />
					  --<input type="text" id="endImg" name="edDate" size="10" readonly="readonly" value="<%=vo.getEdDate()==null?"":vo.getEdDate()%>" onclick="fPopCalendar(document.getElementById('endImg'),document.getElementById('endImg'));return false;" onkeydown="iniTxt_OnKeydown(event,this);" />
						</td>
					</tr>
				</table>
				</div>
				<!--表头搜索条结束-->
				<div class="mainSearchBox">
				  <table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
				    <tr id="moresearchCon"><td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				    <tr id="moresearchCon"><td class="title" width="160">个人应得计算公式:</td><td></td><td></td></tr>
				    <tr id="moresearchCon"><td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				    <tr id="moresearchCon"><td class="title">(一线)</td><td class="title" width="120">团均(<font color=red><%=groupJun%></font>) = </td><td align="left">总创利合计(<font size="+1" color=red><%=rewardProfit.getProfitTotal()==null?"":rewardProfit.getProfitTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></font>) * 15% / 总团数(<font size="+1" color=red><%=rewardProfit.getTotalGroupNum()==null?"":rewardProfit.getTotalGroupNum()%></font>)</td></tr>
				    <tr id="moresearchCon"><td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				    <tr id="moresearchCon"><td></td><td class="title" width="90">个人应得 = </td><td align="left">团均 * 个人团数 - 个人创利总计 * 15% - 个人奖励总计</td></tr>
				    <tr id="moresearchCon"><td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				    <tr id="moresearchCon"><td class="title">(二线)</td><td class="title" width="120">个人应得 = </td><td align="left">个人创利总计 + 个人奖励总计</td></tr>
				    <tr id="moresearchCon"><td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				  </table>
				</div>
				
				<div id="mainListCon">
						<div class="infoCon clearfix">
						    <div class="leftCon">以下是符合条件的旅游团列表</div>
						    <div class="rightCon">共有 <span class="num"><%=pageObj.getRowCnt()%></span> 条信息</div>
					    </div>
						<div class="tableCon">
						<table width="100%" border="0" cellpadding="0" cellspacing="0" id="TalentResumeList" class="listTab">
							<tr class="tabHead">
								<td class="blankTd">项</td><!--从0开始算至第10项，所以性别从第11项开始算-->
								<td width="50" class="centerAlign" nowrap=nowrap>导游编号</td>
								<td nowrap=nowrap class="centerAlign">导游姓名</td>
								<td width="80" class="centerAlign" nowrap=nowrap>导游类型</td>
								<td width="80" class="centerAlign" nowrap=nowrap>团数</td>
								<td width="80" class="centerAlign" nowrap=nowrap>创利总计(元)</td>
								<td width="100" class="centerAlign" nowrap=nowrap>奖励总计(元)</td>
								<td width="75" class="centerAlign" nowrap=nowrap>个人应得(元)</td>
							</tr>
						  <%
							 int i=0;
							   for(Object obj : pageObj.getPageList()){
							   i++;
							     StatisticsPojo statistic = (StatisticsPojo)obj;
							  %>
							<tr class='<%=i%2==0?"list1":"list2"%>'>
								<td class="tdCheckbox">
								  <%=i%>
								</td>
								<td class="centerAlign"><%=statistic.getGuideId()%></td>
								<td class="centerAlign"><a target="_blank" href="<%=basePath%>work/tourist.jsp?dateCode=3&stDate=<%=vo.getStDate()==null?"":vo.getStDate()%>&edDate=<%=vo.getStDate()==null?"":vo.getEdDate()%>&searchCode=3&searchKeyword=<%=statistic.getGuideId()%>"><%=statistic.getGuideName()%></a></td>
								<td class="centerAlign"><%=null==statistic.getGuideType()?"":statistic.getGuideType()+"线"%></td>
								<td class="centerAlign"><%=statistic.getGroupNum()%>个</td>
								<td class="centerAlign"><%=statistic.getProfitTotal()==null?"":statistic.getProfitTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></td>
								<td class="centerAlign"><%=statistic.getRewardTotal()==null?"":statistic.getRewardTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></td>
								<td class="centerAlign">
								  <%
								     if(statistic.getGuideType()!=null){
								         if(statistic.getGuideType()==1){
								             RewardCounter counter = new FirstGuideTypeCounter();
								             BigDecimal perReward = counter.countReward(statistic,rewardProfit).setScale(2,BigDecimal.ROUND_HALF_UP);
								             if(perReward==null)
								               out.print("<font color='#ff8000'>0.00</font>");
								             else if(perReward.compareTo(new BigDecimal(6000))>0){
								               out.print("<font color='green'>"+perReward+"</font>");
								               personGetTotal = personGetTotal.add(perReward);
								             }else{ 
								               personGetTotal = personGetTotal.add(perReward);
								               out.print("<font color='red'>"+perReward+"</font>");
								               }
								         }else{
								             RewardCounter counter = new SecondGuideTypeCounter();
								             BigDecimal perReward = counter.countReward(statistic,rewardProfit).setScale(2,BigDecimal.ROUND_HALF_UP);
								             if(perReward==null)
								               out.print("<font color='#ff8000'>0.00</font>");
								             else if(perReward.compareTo(new BigDecimal(6000))>0){
								               personGetTotal = personGetTotal.add(perReward);
								               out.print("<font color='green'>"+perReward+"</font>");
								             }else{
								               personGetTotal = personGetTotal.add(perReward);
								               out.print("<font color='red'>"+perReward+"</font>");
								             }
								         }
								      
								     }
								   %>
							    </td>
							</tr>
							<%} %>
							<tr bgcolor="lightgreen" >
								<td class="tdCheckbox"></td>
								<td colspan=2 class="centerAlign" nowrap=nowrap><h3>总计:</h3></td>
								<td nowrap=nowrap align="right" colspan="6">
								 <%if(showAll){ %>
								   团均：<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=groupJun%></font>&nbsp;&nbsp;&nbsp;&nbsp;  
								   总团数：<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=rewardProfit.getTotalGroupNum()==null?"":rewardProfit.getTotalGroupNum()%></font>&nbsp;&nbsp;&nbsp;&nbsp;  
								  <% } %>
								   创利总计:<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=rewardProfit.getProfitTotal()==null?"":rewardProfit.getProfitTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%> </font>&nbsp;&nbsp;&nbsp;&nbsp;  
								   奖励总计:<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=rewardProfit.getRewardTotal()==null?"":rewardProfit.getRewardTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></font>&nbsp;&nbsp;&nbsp;&nbsp; 
								   应得总计：<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=personGetTotal==null?"":personGetTotal.setScale(2,BigDecimal.ROUND_HALF_UP) %></font>
								</td>
							</tr>
							<tr align="center">
								<td colspan="11"></td>
							</tr>
						</table>
						</div>
						<!--@BeginSHOWPAGE-->
						<div class="turnpageCon clearfix">
							<div class="turnpage">
							<input type="hidden" id="curPage" name="curPage" value="${vo.curPage}"/>
							<%=pageObj.getSimpleBar()%>
						    </div>
						</div>
						<div class="bottomControl">
						   <input type="button" value="打印" class="genButton6" onclick="printStatisitics()"/>&nbsp;
						   <input type="button" value="导出Excel" class="genButton6" onclick="outputExcel()"/>&nbsp;
						</div>
						<!--@EndSHOWPAGE-->
				</div>
				</form>
			</div>
		</fieldset>
	</div>
	<jsp:include page="../common/Foot.jsp"></jsp:include>
</div>
<script src="<%=basePath%>js/PaginatedTools.js"></script>
<script src="<%=basePath%>dwr/interface/touristManager.js"></script>
<script src="<%=basePath%>dwr/engine.js"></script>
<script src="<%=basePath%>js/jquery.js"></script>
<script language="javascript" type="text/javascript">
var errorHandle = function(err){
     alert(err);
};
dwr.engine.setErrorHandler(errorHandle); 

var formSubmit = function (curPage){
  $("#curPage").val(curPage);
  document.TalentLibForm.submit();
};
function printStatisitics(){
		window.focus();
		window.print();
}
PaginatedTools.setCallBackFun(formSubmit);

function outputExcel(){
   document.TalentLibForm.action="<%=basePath%>work/statisticsImport.jsp";
   document.TalentLibForm.submit();
}
</script>
</body>
</html>
